home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / ansi / stdio / ungetc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-26  |  437 b   |  27 lines

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <libc/file.h>
  4.  
  5. int
  6. ungetc(int c, FILE *f)
  7. {
  8.   if (c == EOF
  9.       || (f->_flag & (_IOREAD|_IORW)) == 0
  10.       || f->_ptr == NULL
  11.       || f->_base == NULL)
  12.     return EOF;
  13.  
  14.   if (f->_ptr == f->_base)
  15.   {
  16.     if (f->_cnt == 0)
  17.       f->_ptr++;
  18.     else
  19.       return EOF;
  20.   }
  21.  
  22.   f->_cnt++;
  23.   *--f->_ptr = c;
  24.  
  25.   return c;
  26. }
  27.